

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>设置我的资料</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
</head>
<body>

  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md12">
        <div class="layui-card">
          <div class="layui-card-header">设置我的资料</div>
          <div class="layui-card-body" pad15>
            
            <div class="layui-form" lay-filter="">
              <div class="layui-form-item">
                <label class="layui-form-label">用户名</label>
                <div class="layui-input-inline">
                  <input type="text" name="loginName" id="loginName" readonly class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">不可修改。一般用于后台登入名</div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">昵称</label>
                <div class="layui-input-inline">
                  <input type="text" name="nickName" lay-verify="nickname" id="nickName" autocomplete="off" placeholder="请输入昵称" class="layui-input">
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">性别</label>
                <div class="layui-input-block">
                  <input type="radio" name="gender" value="male" id="male" title="男">
                  <input type="radio" name="gender" value="famale" id="famale" title="女">
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">手机</label>
                <div class="layui-input-inline">
                  <input type="text" name="mobile" id="mobile" lay-verify="phone" autocomplete="off" class="layui-input">
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">邮箱</label>
                <div class="layui-input-inline">
                  <input type="text" name="email" id="email" lay-verify="email" autocomplete="off" class="layui-input">
                </div>
              </div>
              <div class="layui-form-item">
                <div class="layui-input-block">
                  <button class="layui-btn" lay-submit lay-filter="setmyinfo">确认修改</button>
                  <button type="reset" class="layui-btn layui-btn-primary">重新填写</button>
                </div>
              </div>
            </div>
            
          </div>
        </div>
      </div>
    </div>
  </div>

  <script src="../../../layuiadmin/layui/layui.js"></script>  
  <script>
  layui.config({
    base: '../../../layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'set'], function(){
      var $ = layui.$
      ,setter = layui.setter
      ,form = layui.form
      ,admin = layui.admin

      //请求用户信息接口
      admin.req({
        url: layui.setter.apiHost + '/admin/api/profile'
        ,done: function(res){
          var currentAdmin = res.data;
          if (currentAdmin){
            $("#loginName").val(currentAdmin.loginName);
            $("#nickName").val(currentAdmin.nickName);
            $("#" + currentAdmin.gender).attr("checked", "checked");
            $("#mobile").val(currentAdmin.mobile);
            $("#email").val(currentAdmin.email);

            form.render();
          }
        }
      });

      //提交
      form.on('submit(setmyinfo)', function(obj){
        //请求修改登录用户信息接口
        admin.req({
          url: layui.setter.apiHost + '/admin/api/update'
          ,method: "POST"
          ,data: JSON.stringify(obj.field)
          ,done: function(res){
            //修改成功的提示
            layer.msg('修改成功', {
              offset: '15px'
              ,icon: 1
              ,time: 1000
            });
          }
        });
      });
    });
  </script>
</body>
</html>